let regCall = /^1(3|4|5|6|7|8|9)\d{9}$/;
var regEmail = new RegExp("^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$");

function Regular() {
	// 验证手机号码
	this.mobilePhone = function(call) {
		if (typeof call === 'string' && !regCall.test(call)) {
			return true
		} else {
			return false;
		}
	}
	// 验证邮箱
	this.verifyMail = function(email) {
		if (typeof email === 'string' && !regEmail.test(email)) {
			return true
		} else {
			return false;
		}
	}
}

// 表单判断空字段
function judge(judgeData, obj) {
	let arr = [];
	if (typeof judgeData === 'object') {
		for (let key in judgeData) {
			if (!judgeData[key]) {
				if (obj[key]) {
					arr.push(obj[key])
				}
			}
		}
	}
	return arr
}

// 比较两个日期的大小
function compareDate(date1, date2) {
	var oDate1 = new Date(date1);
	var oDate2 = new Date(date2);

	if (oDate1.getTime() > oDate2.getTime()) {
		return 1;
	} else {
		return 0;
	}
}


//千分号加逗号，即个位数开始每隔三位数，就用逗号隔开，如：numFormat(10000000.01)，输出10,000,000.01
function numFormat(num) {
	if (num == null) {
		return;
	}
	if (!isNaN(num)) {
		num = num.toString();
	}
	if (num.indexOf('.') != -1) {
		var decimals = num.split('.')[1];
		return (
			(parseInt(Number(num)) + '').replace(
				/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g,
				'$&,'
			) +
			'.' +
			decimals.substring(0, 2)
		);
	} else {
		return (parseInt(Number(num)).toFixed(0) + '').replace(
			/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g,
			'$&,'
		);
	}
}

module.exports = {
	Regular: Regular,
	judge: judge
}
